#ifndef UTI_ORDERANDSYS_MAP_H_
#define UTI_ORDERANDSYS_MAP_H_
#pragma once
#include "sys_config.h"
#include "uti_ordersysmap.h"
#include "uti_memman.h"




typedef struct OrderSysMapSerInfo
{
	unsigned int sersize;
	void (*p)();

}OrderSysMapSerInfo;


typedef struct OrderMapSerProfit
{
	OrderMapSerProfit()
	{
		memset(data, 0, sizeof(data));
		memset(inst, 0, sizeof(inst));

		buyopen_amount = 0;
		buyopen_vol = 0;
		buyclose_amount = 0;
		buyclose_vol = 0;
		buy_profit = 0;
		buyopen_commision = 0;
		buyclose_commision = 0;

		sellopen_amount = 0;
		sellopen_vol = 0;
		sellclose_amount = 0;
		sellclose_vol = 0;
		sell_profit = 0;
		sellopen_commision = 0;
		sellclose_commision = 0;

		totalprofit = 0;

	}



	char data[20];
	char inst[10];

	double buyopen_amount;
	double buyopen_vol;
	double buyclose_amount;
	double buyclose_vol;
	double buy_profit;
	double buyopen_commision;
	double buyclose_commision;
	double sellopen_amount;
	double sellopen_vol;
	double sellclose_amount;
	double sellclose_vol;
	double sell_profit;
	double sellopen_commision;
	double sellclose_commision;

	double totalprofit;
}OrderMapSerProfit;

class OrderSysMapSeries
{
public:

	//OrderSysMapSeries(OrderSysMapSerInfo* pserinfo);

	OrderSysMapSeries(unsigned int sersize, void (*p)());

	~OrderSysMapSeries();

	void Addorder(TThostFtdcInstrumentIDType* pinst, TThostFtdcOrderRefType* porderref, TThostFtdcVolumeType reqvol, TThostFtdcDirectionType direct,
		char offset);

	bool FindorderAndSet(CThostFtdcOrderField* porder);

	bool Findorder_exch_sys_setvol(CThostFtdcTradeField* ptrade);

	bool Getmap(TThostFtdcOrderRefType* porder, OrderSysMap* &poutmap);

	bool Getmap_New(TThostFtdcOrderRefType porder, OrderSysMap* &poutmap);

	bool Addreqcanvol(TThostFtdcOrderRefType* orderref, TThostFtdcExchangeIDType* exchangeId, TThostFtdcOrderSysIDType* ordersysId);

	bool Findcancelorderforsucc(CThostFtdcOrderField* porder);

	bool Findcancelorderforfailed(CThostFtdcInputOrderActionField* pinputorderaction);

	//CThostFtdcInstrumentCommissionRateField*> &mapcommisionrate

	bool Setcommisionrate(CThostFtdcInstrumentCommissionRateField* pfield);

	bool GetOrdermapserProfit(OrderMapSerProfit& profit);

public:
	OrderSysMap* m_pmapcur;//point to last bar of series, this bar may not complete(could be control by value of BarData.isend)

	unsigned int m_mapindex;// if m_pcur is avaliable, its value is >=0. ;
	// used to find other avaliable BarDate before m_pcur, for example used to caculate MA(5)

	OrderSysMapSerInfo m_mapserinfo;


private:
	MemMan<OrderSysMap>* m_pmemman; // memory management class of BarSeries. used to store Bar Series data. last bar is m_pobarcur. 

	CThostFtdcInstrumentCommissionRateField* m_psercommision;
	//CStrategySys* m_strategy_sys;

};




#endif





